﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;

namespace Hoons_Player
{
    class Music
    {
        public static List<Music> Musics=new List<Music>();
        public string SongName { get; set; }
        public string SingerName { get; set; }
        public string AlbumName { get; set; }
        public BitmapImage AlbumArt { get; set; }
        public string Path { get; set; }
        public int ColSpan{ get; set;}
        public int RowSpan { get; set; }
        public Music(string SongName,string Path, StorageItemThumbnail AlbumArt)
        {
            this.SongName = SongName;
            this.Path = Path;
            this.ColSpan = 1;
            this.RowSpan = 1;
            this.AlbumArt = new BitmapImage();
            this.AlbumArt.SetSource(AlbumArt);
        }

        static public async Task GetMusics()
        {
            StorageFolder storageFolder = KnownFolders.MusicLibrary;
            var x=await storageFolder.GetFilesAsync();
            foreach (var y in x)
            {
                MusicProperties properties = await y.Properties.GetMusicPropertiesAsync();
//                this.OutputStatus.Text += "앨범: " + properties.Album + "\n";
//                this.OutputStatus.Text += "아티스트: " + properties.Artist + "\n";
                const ThumbnailMode thumbnailMode = ThumbnailMode.MusicView;
                const uint size = 100;
                StorageItemThumbnail thumbnail = await y.GetThumbnailAsync(thumbnailMode, size);
               
                    // Also verify the type is ThumbnailType.Image (album art) instead of ThumbnailType.Icon
                    // (which may be returned as a fallback if the file does not provide album art)
                    if (thumbnail != null && thumbnail.Type == ThumbnailType.Image)
                    {
                        // Display the thumbnail
                        //Constants.DisplayResult(ThumbnailImage, OutputStatus, thumbnailMode.ToString(), size, files[0], thumbnail, false);
                    }
                    else
                    {
                        //rootPage.NotifyUser(Errors.NoAlbumArt, NotifyType.StatusMessage);
                    }


                    if (y.Attributes != FileAttributes.Directory)
                    {
                        if(properties.Title=="")
                            Musics.Add(new Music(y.Name, y.Path, thumbnail));
                        else
                            Musics.Add(new Music(properties.Title, y.Path, thumbnail));
                    }
            }
        }
    }
    
}
